/*
 * @Author: fhw
 * @Date: 2022-07-18 16:11:32
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-02-04 00:02:57
 * @Description: 评论
 */
import { ApiProperty } from '@nestjs/swagger';
import { ChatUser } from 'src/chat_user/entities/chat_user.entity';
import {
  Entity,
  Column,
  PrimaryGeneratedColumn,
  ManyToOne,
  OneToMany,
  CreateDateColumn,
  UpdateDateColumn,
  JoinColumn,
} from 'typeorm';
import { ArticleList } from '../../article/entities/article.entity';
import { PaginatedResult } from '../../common/entities/entities';
@Entity('article_comment')
export class CommentList {
  @ApiProperty({ example: 'id', description: 'id' })
  @PrimaryGeneratedColumn()
  id: number;
  @ApiProperty({ example: 'content', description: '评论内容' })
  @Column({
    type: 'varchar',
    length: 256,
    comment: '评论内容',
  })
  content: string;

  @ApiProperty({ example: 'like_num', description: '点赞数' })
  @Column({ type: 'int', default: () => 0, comment: '点赞数' })
  like_num: string;


  @ApiProperty({ example: 'user_id', description: '用户ID' })
  @Column({ type: 'varchar', comment: '用户ID' })
  userId: number;
  @ManyToOne(() => ChatUser, (user) => user.id)
  @JoinColumn()
  user: ChatUser;

  @ApiProperty({ example: 'date', description: '创建时间' })
  @CreateDateColumn({
    type: 'datetime',
    comment: '创建时间',
  })
  createDate: string;

  @ApiProperty({ example: 'updateDate', description: '更新时间' })
  @UpdateDateColumn({
    type: 'datetime',
    comment: '更新时间',
  })
  updateDate: string;

  @ApiProperty({ example: 'to_user_id', description: '被评论用户id' })
  @Column({ type: 'varchar', nullable: true, comment: '被评论用户id' })
  toUserId: number;
  @ManyToOne(() => ChatUser, (user) => user.id)
  @JoinColumn()
  toUser: ChatUser;

  @ApiProperty({ example: 'commentId', description: '评论id' })
  @Column({ type: 'bigint', nullable: true, comment: '评论id' })
  commentId: number;
  // 关联二级评论
  @ManyToOne(() => CommentList, (comment) => comment.id)
  comment: CommentList;

  @ApiProperty({ example: 'email', description: '用户邮箱' })
  @Column({ type: 'varchar', comment: '用户邮箱', nullable: true })
  email: string;

  // 文章关联
  @ApiProperty({ example: 'articleId', description: '文章id' })
  @Column({ type: 'int', comment: '文章id' })
  articleId: number;

  @ManyToOne(() => ArticleList, (article) => article.id)
  article: ArticleList;

  @ApiProperty({ example: 'comment', description: '回复评论',nullable:true })
  @OneToMany(() => CommentList, (comment) => comment.comment)
  replys?: CommentList;
}
export class CommentResult extends PaginatedResult {
  @ApiProperty({
    example: CommentList,
    type: [CommentList],
  })
  data: CommentList[];
  @ApiProperty({ example: 'pageSize', description: '数量' })
  pageSize: number;
  @ApiProperty({ example: 'pageNum', description: '页数' })
  pageNum: number;
  @ApiProperty({ example: 'total', description: '总数' })
  total: number;
}
